CROSS_COMPILE 	?= arm-linux-gnueabihf-
TARGET		?= 3168

CC 			:= $(CROSS_COMPILE)gcc
LD			:= $(CROSS_COMPILE)ld
OBJCOPY 		:= $(CROSS_COMPILE)objcopy
OBJDUMP 		:= $(CROSS_COMPILE)objdump

INCDIRS 		:= imx6ull \
                   stdio/include\
				   	drv/delay \
					drv/clk \
		            drv/gic \
		            drv/led \
		            drv/uart \
					drv/key \
			    drv/i2c \
			    drv/ft3x68\
			    app
				 
				   			   
SRCDIRS			:= project \
                   stdio/lib\
				   drv/delay \
				   drv/clk \
		           drv/gic \
		           drv/led \
		           drv/uart \
				   drv/key \
			       drv/i2c \
		           drv/ft3x68 \
				   app 
				   
				   
INCLUDE			:= $(patsubst %, -I %, $(INCDIRS))

SFILES			:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES			:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))

SFILENDIR		:= $(notdir  $(SFILES))
CFILENDIR		:= $(notdir  $(CFILES))

SOBJS			:= $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS			:= $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS			:= $(SOBJS) $(COBJS)

VPATH			:= $(SRCDIRS)



CFLAGS 		:= -Wall
CPPFLAGS   	:= -nostdinc -fno-builtin $(INCLUDE)
LDFLAGS         := -L /home/book/100ask_imx6ull_sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/6.2.1/ -lgcc


.PHONY: clean
	
$(TARGET).bin : $(OBJS)
	$(LD) -Timx6ull.lds -o $(TARGET).elf $^  $(LDFLAGS)
	$(OBJCOPY) -O binary -S $(TARGET).elf $@
	$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
	./tools/mkimage -n ./tools/imximage.cfg.cfgtmp -T imximage -e 0x80100000 -d $(TARGET).bin $(TARGET).imx
	dd if=/dev/zero of=1k.bin bs=1024 count=1
	cat 1k.bin $(TARGET).imx > $(TARGET).img

$(SOBJS) : obj/%.o : %.S
	$(CC)  $(CFLAGS) -Wa,-mimplicit-it=thumb $(CPPFLAGS)  -c -O2 -o $@ $<

$(COBJS) : obj/%.o : %.c
	$(CC)   $(CFLAGS) -Wa,-mimplicit-it=thumb $(CPPFLAGS)  -c -O2 -o $@ $<
	
clean:
	rm -rf $(TARGET).elf $(TARGET).dis   $(TARGET).img $(TARGET).imx   $(TARGET).bin $(COBJS) $(SOBJS)

	















	
